import bpy
from bpy.types import Operator
from 全局控制.Node.节点和插座基类.bl_UpdateNode import *
import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类

类型枚举 = [
	("TYPE_手动", "手动", "", 0),
	("标识_逐帧", "逐帧", "", 1),
]


class C_SceneNode_更新方式切换(基类.C_SN_基类):
	bl_dname = 'bl_node_更新方式切换'
	bl_label = '更新方式切换'

	m_方式切换 = bpy.props.EnumProperty(items = 类型枚举, name="更新方式", default="TYPE_手动" )
	m_帧间隔 = bpy.props.IntProperty(default=1)
	
	def init(self, context):
		super(C_SceneNode_更新方式切换, self).__init__()
		self.inputs.new('C_NodeSocket_物体', name='要更新节点:')
		self.outputs.new('C_NodeSocket_物体', name='要更新节点:')
		self.type = 'UPDATE_SWITCH_TYPE'

	def draw_buttons(self, context, layout):
		layout.prop(self, "m_方式切换")
		if self.m_方式切换 == '标识_逐帧' :
			layout.prop(self, "m_帧间隔")
	
	def f_update(self):
		if self.m_方式切换 == '标识_逐帧' :
			if bpy.context.scene.frame_current % self.m_帧间隔 :
				super(C_SceneNode_体素物体, self).f_update()



class C_NODE_MENU_更新方式切换(bpy.types.Operator):
	bl_idname = 'node.global_node_switch_update_type'
	bl_label = 'Add 更新方式切换'
	bl_options = {'REGISTER', 'UNDO'}

	def execute(operator, context):
		operator.use_transform = True
		bpy.ops.node.add_node(type='C_SceneNode_更新方式切换', use_transform=True)
		return {'FINISHED'}



classes = (
	C_SceneNode_更新方式切换,
	C_NODE_MENU_更新方式切换,
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)

	
